﻿using PHRClient.PatientForms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PHRClient
{
    public partial class NewRecord : Form
    {
        public NewRecord()
        {
            InitializeComponent();
            this.TopLevel = false;
            this.AutoScroll = true;
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            this.Dock = DockStyle.Fill;

        }

        public void button1_Click(object sender, EventArgs e)
        {
            try
            {
                PatientData userData = new PatientData();
                userData.UserId = Validator.patient.PatientId;

                userData.RecordDate = DateTime.Today.ToString("MM/dd/yyyy");

                if (this.weightTB.Text != null)
                    userData.Weight = Convert.ToInt32(this.weightTB.Text);

                if (this.BodyTempTB.Text != null)
                    userData.BodyTemp = Convert.ToInt32(this.BodyTempTB.Text);

                if (this.HeartRateTB.Text != null)
                    userData.HeartRate = Convert.ToInt32(this.HeartRateTB.Text);

                if (this.BPSysTB.Text != null)
                    userData.BloodPressureSys = Convert.ToInt32(this.BPSysTB.Text);

                if (this.BPDiaTB.Text != null)
                    userData.BloodPressureDia = Convert.ToInt32(this.BPDiaTB.Text);

                if (this.CholestrolHdlTB.Text != null)
                    userData.CholestrolHdl = Convert.ToInt32(this.CholestrolHdlTB.Text);

                if (this.CholestrolLdlTB.Text != null)
                    userData.CholestrolLdl = Convert.ToInt32(this.CholestrolLdlTB.Text);

                if (this.CholestrolTriTB.Text != null)
                    userData.CholestrolTri = Convert.ToInt32(this.CholestrolTriTB.Text);

                if (this.PulseRateTB.Text != null)
                    userData.PulseRate = Convert.ToInt32(this.PulseRateTB.Text);

                if (this.GlucoseTB.Text != null)
                    userData.Glucose = Convert.ToInt32(this.GlucoseTB.Text);


                var products = new PatientDataCollection();
                products.Add(userData);
                products.Save(PatientDataLoader.XMLFILE);

                MessageBox.Show("Data Successfully Added!");
                PHRDetails._addDetails = new AddDetails();
                PHRDetails._addDetails.Show();
            }
            catch (Exception)
            {
                MessageBox.Show("Data Adding Error!, Please Fill All Fields in Daily Details!!");
            }
        }
    }
}
